<template>
    <div class="commoninfo">
        <Modal width="85%" :title="titleName" v-model="formModel" :footer-hide="true" :open-model="formModel=true"
               @on-cancel="cancel"
               class="model" :mask-closable="false">
            <Form ref="formData" :model="formData" :rules="formDataValiate" :label-width="100"
                  :disabled="isShowDetails" style="max-height: 450px;overflow: auto;margin-top: 20px;">
                <div style="padding:0 30px">
                    <div>
                        <h2 class="levellow_title">基本信息</h2>
                        <div>
                            <Row>
                                <Col span="8">
                                    <FormItem label="与主借人关系" prop="custRelation">
                                        <Select v-model="formData.custRelation" clearable placeholder="请选择"
                                                :disabled="isReconsider">
                                            <Option :value="item.value" v-for="(item,index) in custRelationList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="客户姓名" prop="custName">
                                        <Input v-model="formData.custName" clearable maxlength="32"
                                               @on-change="spell()"
                                               :disabled="formData.riskQueriedFlag||isSuggestRejectF||isReconsider||isSendBackToDealer"
                                               placeholder="请输入"/>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="拼音/英文" prop="spellName">
                                        <Input v-model="formData.spellName" clearable maxlength="25"
                                               :disabled="isReconsider"
                                               placeholder="请输入"/>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem label="证件类型" prop="certType">
                                        <Select v-model="formData.certType" clearable placeholder="请选择"
                                                :disabled="formData.riskQueriedFlag||isReconsider||isSendBackToDealer"
                                                @on-change="singleSelectCertType">
                                            <Option :value="item.value" v-for="(item,index) in certTypeList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="证件号码" prop="certNo">
                                        <Input v-model="formData.certNo" clearable maxlength="32"
                                               @on-change="certNoChange"
                                               :disabled="formData.riskQueriedFlag||isSuggestRejectF||isReconsider||isSendBackToDealer"
                                               placeholder="请输入"/>
                                        <Button type="primary" @click="tagEleAuth"
                                                :disabled="isNotCertNo||isBack">电子授权
                                        </Button>
                                    </FormItem>
                                </Col>
                                <Col span="8" class="pr">
                                    <FormItem label="证件到期日"
                                              :rules="formData.isLongTerm?clearCertEndDate:requireCertEndDate"
                                              prop="certEndDate">
                                        <DatePicker type="date" @on-change="getDate" v-model="formData.certEndDate"
                                                    format="yyyy-MM-dd"
                                                    placeholder="请选择证件到期日"
                                                    :disabled="formData.isLongTerm||isReconsider"></DatePicker>
                                    </FormItem>
                                    <FormItem label="" prop="isLongTerm" :label-width="0"
                                              style="position: absolute;left:320px;width:60px;top:0px">
                                        <Checkbox v-model="formData.isLongTerm" @on-change="selectCheckBox"
                                                  :disabled="isReconsider"> 长期
                                        </Checkbox>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem label="出生日期" prop="birthday">
                                        <DatePicker type="date" v-model="formData.birthday"
                                                    placeholder="请选择" :disabled="isReconsider"
                                                    @on-change="countAge(formData.birthday)"></DatePicker>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="户籍地址" prop="domicLocation">
                                        <Cascader :data="location" v-model="formData.domicLocation"
                                                  :load-data="loadData" :disabled="isReconsider"
                                                  style="margin-top: 4px;"
                                        ></Cascader>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="婚姻状况" prop="maritalStatus">
                                        <Select v-model="formData.maritalStatus" clearable placeholder="请选择婚姻状况"
                                                :disabled="isReconsider"
                                        >
                                            <Option :value="item.value" v-for="(item,index) in maritalStatusList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem label="性别" prop="sex">
                                        <Select v-model="formData.sex" clearable placeholder="请选择性别"
                                                :disabled="isReconsider">
                                            <Option :value="item.value" v-for="(item,index) in sexList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="国籍" prop="nationality">
                                        <Select v-model="formData.nationality" clearable placeholder="请选择国籍"
                                                :disabled="isReconsider"
                                        >
                                            <Option :value="item.value" v-for="(item,index) in nationalityList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="学历" prop="highestEducation">
                                        <Select v-model="formData.highestEducation" clearable placeholder="请选择学历"
                                                :disabled="isReconsider">
                                            <Option :value="item.value" v-for="(item,index) in highestEducationList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem label="手机号码" prop="telPhone">
                                        <Input v-model="formData.telPhone" clearable maxlength="11"
                                               @on-change="isSignOk" :disabled="isReconsider"
                                               placeholder="请输入"/>
                                    </FormItem>
                                </Col>
                            </Row>
                        </div>
                    </div>
                    <div>
                        <h2 class="levellow_title">工作信息</h2>
                        <div>
                            <Row>
                                <Col span="8">
                                    <FormItem label="单位名称" prop="unitName">
                                        <Input v-model="formData.unitName" clearable maxlength="128"
                                               :disabled="isReconsider"
                                               placeholder="请输入"/>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="单位性质" prop="unitNature">
                                        <Select v-model="formData.unitNature" clearable placeholder="请选择单位性质"
                                                :disabled="isReconsider"
                                        >
                                            <Option :value="item.value" v-for="(item,index) in unitNatureList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="行业类型" prop="industryType">
                                        <Select v-model="formData.industryType" clearable placeholder="请选择行业类型"
                                                :disabled="isReconsider"
                                        >
                                            <Option :value="item.value" v-for="(item,index) in industryTypeList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem label="职业类型" prop="jobsType">
                                        <Select v-model="formData.jobsType" clearable placeholder="请选择职业类型"
                                                :disabled="isReconsider">
                                            <Option :value="item.value" v-for="(item,index) in jobsTypeList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="职务" prop="position">
                                        <Select v-model="formData.position" clearable placeholder="请选择职务"
                                                :disabled="isReconsider">
                                            <Option :value="item.value" v-for="(item,index) in positionList"
                                                    :key="index">{{item.title}}
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="本人月收入" prop="monthlyIncome">
                                        <Input v-model="formData.monthlyIncome" clearablemaxlength="11"
                                               :disabled="isReconsider"
                                               placeholder="请输入"/>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem label="工作年限" prop="workAge">
                                        <Input v-model="formData.workAge" clearable placeholder="请输入"
                                               type="text" :disabled="isReconsider"
                                               maxlength="4"/>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="公司电话" prop="companyPhone">
                                        <Input v-model="formData.companyPhone" clearable maxlength="20"
                                               :disabled="isReconsider"
                                               placeholder="请输入"/>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem label="家庭总收入" prop="totalIncome">
                                        <Input v-model="formData.totalIncome" clearable maxlength="11"
                                               :disabled="isReconsider"
                                               placeholder="请输入"/>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem label="未结清贷款" prop="outstandingLoan">
                                        <Input v-model="formData.outstandingLoan" clearable maxlength="11"
                                               :disabled="isReconsider"
                                               placeholder="请输入"/>
                                    </FormItem>
                                </Col>
                            </Row>
                        </div>
                    </div>
                    <div class="addressmsg">
                        <h2 class="levellow_title">地址信息
                            <Button @click="addLocation"
                            >新增地址
                            </Button>
                        </h2>
                        <div>
                            <div v-for="(item,index) in formData.addressinfo" :key="index" class="adresstype">
                                <h3 v-show="index==0">现居住地址</h3>
                                <h3 v-show="index==1">单位地址<span @click="copyAddressValue(index)"
                                                                v-show="!isShowDetails">一键同上地址</span></h3>
                                <h3 v-show="index>1">地址类型<span class="del" v-show="!isShowDetails"
                                                               @click="deleteAddress(item,index)">删除</span><span
                                    @click="copyAddressValue(index)" v-show="!isShowDetails">一键同上地址</span></h3>
                                <Row>
                                    <Col span="8">
                                        <FormItem label="地址类型" :prop="'addressinfo['+index+'].addressType'">
                                            <Select v-model="item.addressType" clearable placeholder="请选择地址类型"

                                                    :disabled="(formData.addressinfo[index].addressType==='2'&&index<=1)||(formData.addressinfo[index].addressType==='3'&&index<=1)
||isReconsider&&index<=1">
                                                <Option
                                                    :value="item.value"
                                                    v-for="(item,index) in addressTypeList"
                                                    :key="index"
                                                >{{item.title}}
                                                </Option>
                                            </Select>
                                        </FormItem>
                                    </Col>
                                    <Col span="16">
                                        <FormItem
                                            label="详细地址"
                                            :prop="'addressinfo['+index+'].detailAddressTemp'"
                                            class="show_cascader_detail inline-block"
                                            clearable
                                        >
                                            <Cascader
                                                :data="location"
                                                v-model="item.detailAddressTemp"
                                                placeholder="下拉选择省市"
                                                :load-data="loadData"
                                                :clearable="true"
                                                :disabled="isReconsider&&index<=1"
                                            ></Cascader>
                                        </FormItem>
                                        <FormItem
                                            :prop="'addressinfo['+index+'].inputDetail'"
                                            style="width:45%;margin-top: 4px;"
                                            :label-width="0"
                                            clearable
                                            class="inline-block "
                                        >
                                            <Input
                                                v-model="item.inputDetail"
                                                placeholder="请输入详细地址"
                                                clearable
                                                :disabled="isReconsider&&index<=1"
                                                style="vertical-align: top;"
                                                class="wprecent100"
                                                maxlength="128"
                                            />
                                        </FormItem>
                                        <Radio v-model="formData.addressinfo[index].isShow"
                                               v-if="index<=1"
                                               :disabled="formData.addressinfo[index].isDefault&&isReconsider"
                                               @click.native="setIsDefault(index)" style="margin-top: 5px;">邮寄地址
                                        </Radio>
                                    </Col>
                                </Row>
                                <Row v-if="index==0">
                                    <Col span="8">
                                        <FormItem label="房产类型" :prop="'addressinfo['+index+'].houseType'">
                                            <Select v-model="item.houseType" clearable placeholder="请选择房产类型"
                                                    :disabled="isReconsider"
                                            >
                                                <Option
                                                    :value="item.value"
                                                    v-for="(item,index) in houseTypeList"
                                                    :key="index"
                                                >{{item.title}}
                                                </Option>
                                            </Select>
                                        </FormItem>
                                    </Col>
                                    <Col span="8">
                                        <FormItem label="房产起始时间" :prop="'addressinfo['+index+'].houseStartDate'">
                                            <DatePicker
                                                type="date"
                                                v-model="item.houseStartDate"
                                                :disabled="isReconsider"
                                                placeholder="请选择房产起始时间"
                                            ></DatePicker>
                                        </FormItem>
                                    </Col>
                                </Row>
                            </div>
                        </div>
                    </div>
                </div>
            </Form>
            <div class="operBtn">
                <Button type="primary" @click="save('formData')" style="margin-right: 20px;" v-show="!isShowDetails"
                        :loading="loading">
                    保存
                </Button>
                <Button type="primary" @click="cancel" v-show="!isShowDetails">取消</Button>
            </div>
        </Modal>
        <!--编辑弹窗-->
        <Modal v-model="editelectorAuthModel"
               title="电子授权"
               :mask-closable="false"
               :width="1100"
               @on-cancel="cancel"
               @on-ok="submit">
            <div class="electorAuthForm">
                <Form ref="electorAuthForm" :model="electorAuthForm" :rules="electorAuthFormRule" :label-width="120">
                    <Row>
                        <Col span="12">
                            <FormItem label="业务类型:" prop="businessType">
                                <Select v-model="electorAuthForm.businessType" clearable disabled>
                                    <Option value="01" :disabled="isNewCarDisabled">新车</Option>
                                    <Option value="02" :disabled="isOldCarDisabled">二手车</Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col span="12">
                            <FormItem label="手机号码:" prop="telPhone">
                                <Input v-model="electorAuthForm.telPhone" maxlength="11" clearable disabled/>
                            </FormItem>
                        </Col>
                        <Col span="12">
                            <FormItem label="客户姓名:" prop="custName">
                                <Input v-model="electorAuthForm.custName" clearable disabled/>
                            </FormItem>
                        </Col>
                        <Col span="12">
                            <FormItem label="身份证到期日:" prop="certEndDate">
                                <DatePicker type="date" v-model="electorAuthForm.certEndDate" disabled></DatePicker>
                            </FormItem>
                        </Col>
                        <Col span="12">
                            <FormItem label="证件号码:" prop="certNo">
                                <Input v-model="electorAuthForm.certNo" clearable disabled/>
                            </FormItem>
                        </Col>
                    </Row>
                </Form>
            </div>
            <div class="uploadInfo pr editElector">
                <label>影像信息:</label>
                <card-upload ref="editcarUpload" :frontType="contractFrontType" :balckType="contractBlackType"
                             :isPass="isPass"
                             @queryZmInfo="queryZmInfo"
                             @queryFmInfo="queryFmInfo"
                ></card-upload>
            </div>
            <!--二维码展示-->
            <div style="text-align: center" v-if="binary">
                <img id="rcode" :src="'data:image/PNG;base64,'+binary">
                <p style="font-size: 13px;">
                    <Icon type="ios-alert" color="red">
                    </Icon>&nbsp;请扫描二维码进行认证（有效时间:30分钟）
                </p>
            </div>
            <div slot="footer">
                <div v-if="!isPass">
                    <Button type="info" :disabled="isDisabled" v-if="binary"
                            @click="refreshQrCode()">{{codeName}}
                    </Button>
                    <Button size="small" type="info" @click="editTurnBack()"
                            icon="ios-backspace-outline">返回
                    </Button>
                    <Button type="primary" size="small" @click="submit" icon="ios-bookmark">提交</Button>
                </div>
            </div>
        </Modal>
    </div>
</template>
<script>
    import PlaceCascade from "@/components/place-cascade"
    import {getLocation} from "_p/afs-apply/api/apply-report/personal/common.js"
    import {saveCustomerInfo} from "_p/afs-apply/api/apply-report/personal/customInfo.js";
    import {
        deleteAddressInfo,
        updateCustomerInfo,
        updateSignParams
    } from "../../../../../api/apply-report/personal/customInfo";
    import vPinyin from "../../../../../assets/js/vue-py";
    import * as utils from "../../../../../assets/js/utils";
    import {deepClone} from "../../../../../../../libs/utils/ObjectClone";
    import {formatDate} from "../../../../../../../components/iview/components/date-picker/util";
    import CardUpload from "@/components/identitycard-upload";

    export default {
        name: "comoninfo",
        data() {
            return {
                titleName: '',
                contractFrontType: '',
                contractBlackType: '',
                isNotCertNo: false,
                isDisabled: false,
                binary: "",
                isPass: false,
                editelectorAuthModel: false,
                loading: false,
                setIsDefaultName: '设为邮寄地址',
                id: "",//编辑的时候修改id
                location: [],
                formModel: false,
                totalLevel: 2,
                electorAuthForm: {
                    businessType: "",
                    telPhone: "",
                    custName: "",
                    certEndDate: "",
                    certNo: "",
                },
                formData: {
                    id: "",
                    personalInfoId: "",
                    personalAddressId: "",
                    permanentAdreess: [],
                    custRelation: "",
                    custName: "",
                    spellName: "",
                    custType: "",
                    certType: "00001",
                    certNo: "",
                    birthday: "",
                    certEndDate: "",
                    signFailNumber: 0,
                    isLongTerm: false,
                    domicLocation: [],
                    maritalStatus: "",
                    sex: "",
                    age: '',
                    nationality: "00001",
                    workAge: "",
                    highestEducation: "",
                    telPhone: "",
                    unitName: "",
                    unitNature: "",
                    certEndDate: "",
                    industryType: "",
                    jobsType: "",
                    position: "",
                    companyPhone: "",
                    monthlyIncome: "",
                    totalIncome: "",
                    outstandingLoan: "",
                    riskQueriedFlag: false,
                    // 地址信息
                    addressinfo: [
                        {
                            id: "",
                            addressType: "2",
                            detailAddressTemp: [],
                            inputDetail: "",
                            houseType: "",
                            houseStartDate: "",
                            isDefault: false,
                            isShow: false,
                        },
                        {
                            id: "",
                            addressType: "3",
                            detailAddressTemp: [],
                            inputDetail: "",
                            isDefault: false,
                            isShow: false,
                        }
                    ]
                },
                electorAuthFormRule: {
                    businessType: [
                        {required: true, message: "请至少选择一项", trigger: "change"}
                    ],
                    telPhone: [
                        {required: true, message: "手机号码值不能为空", trigger: "change"},
                        {validator: utils.isPhoneValiate, trigger: "change"}
                    ],
                    custName: [
                        {required: true, message: "客户姓名值不能为空", trigger: "change"},
                        {validator: utils.isNameValiate, trigger: "change"}
                    ],
                    certEndDate: [
                        {required: true, type: 'date', message: "身份证到期日值不能为空", trigger: "change"}
                    ],
                    certNo: [
                        {required: true, message: "证件号码值不能为空", trigger: "change"},
                        {validator: utils.doValidID, trigger: "change"}
                    ]
                },
                formDataValiate: {
                    // 基本信息校验
                    companyPhone: [
                        {
                            validator: (rule, value, callback) => {
                                utils.isCheckPhoneAndFixedLinePhone(rule, value, callback)
                            }, trigger: "blur"
                        }
                    ],
                    custRelation: [
                        {required: true, message: "与主借人关系不能为空", trigger: "change"}
                    ],
                    custName: [
                        {required: true, message: "请输入姓名不能为空", trigger: "blur"},
                        {
                            validator: (rule, value, callback) => {
                                utils.isNameValiate(rule, value, callback)
                            }, trigger: "change"
                        }
                    ],
                    spellName: [
                        {required: true, message: "拼音/英文不能为空", trigger: "blur"}
                    ],
                    certType: [
                        {required: true, message: "证件类型不能为空", trigger: "change"}
                    ],
                    certNo: [
                        {required: true, message: "证件号码不能为空", trigger: "change"},
                        {validator: this.validID, trigger: "change",}
                    ],
                    birthday: [
                        {required: true, message: "出生日期不能为空", trigger: "change", type: "date"}
                    ],
                    domicLocation: [
                        {required: true, message: "户籍所在地不能为空", trigger: "change", type: "array"}
                    ],
                    maritalStatus: [
                        {required: true, message: "婚姻状况不能为空", trigger: "change"}
                    ],
                    sex: [
                        {required: true, message: "性别不能为空", trigger: "change"}
                    ],
                    nationality: [
                        {required: true, message: "国籍不能为空", trigger: "change"}
                    ],
                    workAge: [
                        {required: true, message: "工作年限不能为空", trigger: "blur"},
                        {
                            validator: (rule, value, callback) => {
                                utils.isCheckItOutForWorkAge(rule, value, callback)
                            }, trigger: "blur"
                        }
                    ],
                    highestEducation: [
                        {required: true, message: "学历不能为空", trigger: "change"}
                    ],
                    // 工作信息校验
                    unitName: [
                        {required: true, message: "单位名称不能为空", trigger: "blur"},
                    ],
                    unitNature: [
                        {required: true, message: "单位性质不能为空", trigger: "change"},
                    ],
                    industryType: [
                        {required: true, message: "行业类型不能为空", trigger: "change"},
                    ],
                    jobsType: [
                        {required: true, message: "职业类型不能为空", trigger: "change"},
                    ],
                    position: [
                        {required: true, message: "职务不能为空", trigger: "change"},
                    ],
                    monthlyIncome: [
                        {required: true, message: "本人月收入不能为空", trigger: "blur", type: 'string'},
                        {
                            validator: (rule, value, callback) => {
                                utils.isMoneyValue(rule, value, callback)
                            }, trigger: "blur"
                        }
                    ],
                    totalIncome: [
                        {
                            validator: (rule, value, callback) => {
                                utils.isMoneyValue(rule, value, callback)
                            }, trigger: "blur"
                        }
                    ],
                    outstandingLoan: [
                        {
                            validator: (rule, value, callback) => {
                                utils.isMoneyValue(rule, value, callback)
                            }, trigger: "blur"
                        }
                    ],
                    telPhone: [
                        {required: true, message: "手机号码不能为空", trigger: "blur"},
                        {
                            validator: (rule, value, callback) => {
                                utils.isPhoneValiate(rule, value, callback)
                            }, trigger: "blur"
                        }
                    ]
                },
                requireCertEndDate: [
                    {required: true, message: "证件到期日不能为空", trigger: "blur", type: 'date'},
                ],
                clearCertEndDate: [{required: false}],
            }
        },

        props: {
            isReconsider: {
                type: Boolean
            },
            isSendBackToDealer: {
                type: Boolean
            },
            isSuggestRejectF: {
                type: Boolean,
            },
            isBack: {
                type: Boolean,
            },
            custRole: {
                type: String
            },
            tempBusinessType: {
                type: String
            },
            isOldCarDisabled: {
                type: Boolean,
            },
            isNewCarDisabled: {
                type: Boolean,
            },
            isShowDetails: {
                type: Boolean,
            },
            dataList: {},
            details: '',
            certTypeList: {
                type: Array,
                required: true,
            },
            maritalStatusList: {
                type: Array,
                required: true,
            },
            sexList: {
                type: Array,
                required: true,
            },
            highestEducationList: {
                type: Array,
                required: true,
            },
            nationalityList: {
                type: Array,
                required: true,
            },
            drivingTypeList: {
                type: Array,
                required: true,
            },
            unitNatureList: {
                type: Array,
                required: true,
            },
            industryTypeList: {
                type: Array,
                required: true,
            },
            jobsTypeList: {
                type: Array,
                required: true,
            },
            positionList: {
                type: Array,
                required: true,
            },
            addressTypeList: {
                type: Array,
                required: true,
            },
            houseTypeList: {
                type: Array,
                required: true,
            },
            custRelationList: {
                type: Array,
                required: true,
            },
            personalType: {
                type: String,
            },
            applyNo: {
                type: String,
            },
            signResult: {
                type: String,
            }
        },
        components: {
            PlaceCascade,
            CardUpload
        },
        created() {
            this.initCheckAddressValiate();
        },
        mounted() {
            if (this.personalType == '02') {
                this.titleName = '共借人';
            } else {
                this.titleName = '保证人'
            }
            this.getLocationData();
            this.initGetDataList();
            if (this.formData.addressinfo[0].isDefault === false) {
                this.formData.addressinfo[0].isDefault = true;
                this.formData.addressinfo[0].isShow = true;
            }
            if (this.custRole == '02') {
                this.contractFrontType = 'comBorrowerIdcardFront';
                this.contractBlackType = 'comBorrowerIdcardBack';
            } else if (this.custRole == '03') {
                this.contractFrontType = 'guarantorBorrowerIdcardFront';
                this.contractBlackType = 'guarantorBorrowerIdcardBack';
            }
        },
        methods: {

            // 电子授权弹窗
            tagEleAuth() {
                if (this.formData.signFailNumber == 3) {
                    this.$Message.error("电子授权失败次数超过3次，请纸质签署征信授权书文件");
                    return;
                }
                this.editelectorAuthModel = true;
                this.electorAuthForm.businessType = this.tempBusinessType;
                this.electorAuthForm.telPhone = this.formData.telPhone;
                this.electorAuthForm.custName = this.formData.custName;
                this.electorAuthForm.certEndDate = this.formData.certEndDate || "9999-12-31";
                this.electorAuthForm.certNo = this.formData.certNo;
                let self = this;
                this.$nextTick(function () {
                    self.$refs.editcarUpload.resetimgurl();
                    self.$refs.editcarUpload.showCarImg(this.applyNo);
                })
                // 预审批通过
                if (this.signResult && this.signResult == "1") {
                    this.isPass = true;
                    //预审批没通过
                } else {
                    this.isPass = false;
                }
            },
            //电子授权提交
            submit() {
                this.binary = '';
                if (this.refreshTime !== '') {
                    this.destroyed();
                }
                let certEndDate = formatDate(this.electorAuthForm.certEndDate, "yyyy-MM-dd")
                let param = {
                    applyNo: this.applyNo,
                    businessType: this.electorAuthForm.businessType,
                    telPhone: this.electorAuthForm.telPhone,
                    custName: this.electorAuthForm.custName,
                    certEndDate: certEndDate,
                    certNo: this.electorAuthForm.certNo,
                    custRole: this.custRole,
                }
                this.$refs.electorAuthForm.validate((valid) => {
                    if (valid) {
                        this.errorTipScorll('emerContactForm');
                    }
                });
                //影像入参数
                let data = this.queryParam(param, 'edit');
                console.log(data, "影像如参数")
                if (!data) {
                    this.$Message.warning("请上传身份证正反面");
                    return;
                }
                updateSignParams(param).then(res => {
                    if (res.code == "0000") {
                        this.formData.custName = param.custName;
                        this.formData.telPhone = param.telPhone;
                        this.formData.certEndDate = param.certEndDate;
                        this.formData.spellName = vPinyin.chineseToPinYin(param.custName);
                        this.codeName = "刷新二维码";
                        this.binary = res.data[1].code;
                        this.isDisabled = false;
                    }
                })
            },
            // 查询影像上传入参数
            queryParam(datas, type) {
                let imgList = "";
                if (type == 'edit') {
                    imgList = this.$refs.editcarUpload.devierimglist();
                }
                console.log(imgList, "imgList")
                if (imgList.length < 2) {
                    return false;
                }
                if (imgList.length > 0) {
                    let tempArr = [];
                    imgList.forEach((item, index) => {
                        tempArr.push(item.map)
                    })
                    datas.contractFileVos = tempArr;
                }
                return true
            },
            editTurnBack() {
                this.editelectorAuthModel = false;
                this.binary = '';
                this.destroyed();
            },
            cancel() {
                this.editelectorAuthModel = false;
                this.binary = '';
                this.destroyed();
            },
            destroyed() {
                // 清除定时器
                clearInterval(this.countDown)
                this.countDown = null;
            },
            //刷新二维码信息,并更新数据
            refreshQrCode() {
                let v = {};
                this.countDown = setInterval(() => {
                    //如果刷新时间为空，那么就可以点击刷新
                    if (this.refreshTime === '') {
                        this.isDisabled = false;
                        this.codeName = "刷新二维码";
                        this.binary = '';
                        v = {
                            id: this.formData.id,
                            custRole: '01',
                        }
                        //点击刷新
                        refresh(v).then(res => {
                            if (res.code === '0000') {
                                this.binary = '';
                                this.$Message.success("刷新成功");
                                this.refreshTime = res.data.activeTime;
                                this.binary = res.data.code;
                            }
                        })
                    } else {
                        this.isDisabled = true;
                        this.codeName = this.refreshTime-- + 's后再次刷新';
                        // console.log(this.codeName, "this.codeName ")
                    }
                }, 1800);
            },
            queryZmInfo(data) {
                if (data) {
                    this.electorAuthForm.custName = data.name;
                    this.electorAuthForm.certNo = data.number;
                }
            },
            queryFmInfo(data) {
                if (data) {
                    this.electorAuthForm.certEndDate = data.validUntil;
                }
            },
            singleSelectCertType(val) {
                if (val == "00001") {
                    this.formDataValiate['certNo'].push({
                        validator: this.validID,
                        trigger: "blur"
                    })
                    this.isNotCertNo = false;
                } else {
                    this.isNotCertNo = true;
                    let lenValitate = this.formDataValiate['certNo'].length - 1;
                    this.formDataValiate['certNo'].splice(lenValitate, 1)
                }
            },
            //删除地址信息
            deleteAddressInfo(v) {
                console.log("删除地址信息:", v);
                deleteAddressInfo(v).then(res => {
                    if (res.code === '0000') {
                        this.$Message.success("删除成功");
                    }
                })
            },
            //根据证件号，显示或清空生日和性别
            certNoChange() {
                this.formData.certNo = this.formData.certNo.replace(/\s+/g, "");
                if (this.formData.certType == '00001') {
                    this.go(this.formData.certNo);
                }
            },
            initGetDataList() {
                let details = deepClone(this.details);
                console.log("是否置灰:", details);
                let dataList = deepClone(this.dataList);
                if (details != null && details != '') {
                    this.isShowDetails = true;
                }
                //如果获取的dataList的长度大于零,那么就执行下面的方法
                if (dataList != null && dataList != "" || dataList.length > 0) {
                    let _this = this;
                    this.$nextTick(() => {
                        _this.formData = _this.dataList;
                    });
                }
                if (dataList && dataList.length > 0) {
                    this.formData.addressinfo = dataList.addressinfo;
                    for (let i = 0; i < this.formData.addressinfo.length; i++) {
                        if (this.formData.addressinfo[i].isShow === false) {
                            this.formData.addressinfo[i].isDefault = false;
                        } else if (this.formData.addressinfo[i].isShow === true) {
                            this.formData.addressinfo[i].isDefault = true;
                        }
                    }
                }
            },
            copyAddressValue(index) {
                let addressinfo = this.formData.addressinfo;
                console.log(addressinfo, "addressinfo")
                // if (addressinfo[index - 1].addressType) {
                //     addressinfo[index].addressType = addressinfo[index - 1].addressType;
                // }
                if (addressinfo[index - 1].detailAddressTemp.length > 0) {
                    this.$set(addressinfo[index], "detailAddressTemp", addressinfo[index - 1].detailAddressTemp);
                }
                if (addressinfo[index - 1].inputDetail) {
                    addressinfo[index].inputDetail = addressinfo[index - 1].inputDetail
                }
            },
            //年龄计算
            countAge(v) {
                v = formatDate(v, "yyyy-MM-dd")
                var birthdays = new Date(v.replace(/-/g, "/"));
                var d = new Date();
                var age = d.getFullYear() - birthdays.getFullYear() - (d.getMonth() < birthdays.getMonth() || (d.getMonth() == birthdays.getMonth() && d.getDate() < birthdays.getDate()) ? 1 : 0);
                this.formData.age = age;
                console.log("年龄:", this.formData.age)
            },
            //设置邮寄地址
            setIsDefault(index) {
                if (this.isShowDetails) return;
                if (this.formData.addressinfo[index].isShow === true) {
                    this.formData.addressinfo[index].isDefault = true
                } else if (this.formData.addressinfo[index].isShow === false) {
                    this.formData.addressinfo[index].isDefault = false
                }
                if (this.formData.addressinfo[index].isDefault === false) {
                    if (index <= 0) {
                        this.formData.addressinfo[index + 1].isDefault = false;
                        this.formData.addressinfo[index + 1].isShow = false;
                        this.formData.addressinfo[index].isDefault = true;
                        this.formData.addressinfo[index].isShow = true;
                    }
                    if (index >= 1) {
                        this.formData.addressinfo[index - 1].isDefault = false;
                        this.formData.addressinfo[index - 1].isShow = false;
                        this.formData.addressinfo[index].isDefault = true;
                        this.formData.addressinfo[index].isShow = true;
                    }
                    this.$Message.success('邮寄地址设置成功');
                }//更改按钮颜色
            },
            selectCheckBox(value) {
                if (value === true) {
                    this.formData.certEndDate = "";
                }
                if (this.formData.custName != '' && this.formData.certNo != '' && this.formData.telPhone != '' && (this.formData.certEndDate != '' || this.formData.isLongTerm == true)) {
                    console.log("监听进来了")
                    this.isNotCertNo = false;
                } else {
                    this.isNotCertNo = true;
                }
            },
            deleteAddress(item, index) {
                if (index > 1) {
                    this.formData.addressinfo.splice(index, 1);
                    this.deleteAddressInfo(item)
                }
            },
            // 身份证验证
            validID(rule, value, callback) {
                // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
                let reg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
                if (reg.test(value)) {
                    if (this.formData.certType == '00001') {
                        this.go(value.length);
                    }
                    callback()
                } else {
                    callback(new Error('身份证号码不正确'))
                }
            },
            // 实现自动生成生日，性别，年龄
            go(val) {
                if (val === 18) {
                    val = 18;
                } else if (val === 15) {
                    val = 15;
                } else {
                    val = val.length;
                }
                let iden = this.formData.certNo;
                let sex = null;
                let birth = null;
                let myDate = new Date();
                let month = myDate.getMonth() + 1;
                let day = myDate.getDate();
                let age = 0;

                if (val === 18) {
                    sex = iden.substring(16, 17);
                    birth = iden.substring(6, 10) + "-" + iden.substring(10, 12) + "-" + iden.substring(12, 14);
                    if (iden.substring(10, 12) < month || iden.substring(10, 12) == month && iden.substring(12, 14) <= day) age++;

                }
                if (val === 15) {
                    sex = iden.substring(13, 14);
                    birth = "19" + iden.substring(6, 8) + "-" + iden.substring(8, 10) + "-" + iden.substring(10, 12);
                    if (iden.substring(8, 10) < month || iden.substring(8, 10) == month && iden.substring(10, 12) <= day) age++;
                }

                if (sex % 2 === 0)
                    sex = 'F';
                else
                    sex = 'M';
                this.formData.sex = sex;
                if (this.formData.certType == '00001') {
                    this.formData.birthday = new Date(birth);
                } else {
                    this.formData.birthday = null;
                }
                this.countAge(this.formData.birthday);
            },
            //中文转拼音
            spell() {
                if (this.formData.custName != '' && this.formData.certNo != '' && this.formData.telPhone != '' && (this.formData.certEndDate != '' || this.formData.isLongTerm == true)) {
                    console.log("监听进来了")
                    this.isNotCertNo = false;
                } else {
                    this.isNotCertNo = true;
                }
                console.log("dadadasdada")
                this.formData.spellName = vPinyin.chineseToPinYin(this.formData.custName);
                this.$refs.formData.validateField('spellName');
            },
            isSignOk() {
                if (this.formData.custName != '' && this.formData.certNo != '' && this.formData.telPhone != '' && (this.formData.certEndDate != '' || this.formData.isLongTerm == true)) {
                    console.log("监听进来了")
                    this.isNotCertNo = false;
                } else {
                    this.isNotCertNo = true;
                }
            },
            getDate() {
                if (this.formData.custName != '' && this.formData.certNo != '' && this.formData.telPhone != '' && (this.formData.certEndDate != '' || this.formData.isLongTerm == true)) {
                    console.log("监听进来了")
                    this.isNotCertNo = false;
                } else {
                    this.isNotCertNo = true;
                }
            },
            getLocationData() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code === "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.location.push(...res.data);
                })
            },
            loadData(item, callback) {
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
            },
            // 新增地址
            addLocation() {
                let obj = {
                    addressType: "",
                    detailAddressTemp: [],
                    inputDetail: "",
                };
                this.formData.addressinfo.push(obj);
                this.dynamicCheckValiate(this.formData);
            },
            // 动态地址校验
            dynamicCheckValiate(form) {
                this.formDataValiate['addressinfo[' + (form.addressinfo.length - 1) + '].detailAddressTemp'] = [];
                this.formDataValiate['addressinfo[' + (form.addressinfo.length - 1) + '].addressType'] = [];
            },
            // 初始化详细地址校验
            initCheckAddressValiate() {
                for (let i = 0; i < this.formData.addressinfo.length; i++) {
                    this.formDataValiate["addressinfo[" + i + "].addressType"] = [
                        {required: true, message: "请选择地址类型", trigger: "change"}
                    ];
                    this.formDataValiate['addressinfo[' + i + '].detailAddressTemp'] = [
                        {required: true, message: "请选择详细地址", trigger: "change", type: "array"}
                    ]
                    if (i == 0) {
                        this.formDataValiate['addressinfo[' + i + '].addressType'] = [
                            {required: true, message: "请选择地址类型", trigger: "change"}
                        ];
                        this.formDataValiate['addressinfo[' + i + '].houseType'] = [
                            {required: true, message: "请选择房产类型", trigger: "change"}
                        ];
                        this.formDataValiate['addressinfo[' + i + '].houseStartDate'] = [
                            {required: true, message: "请选择房产起始时间", trigger: "change", type: "date"}
                        ]
                    }
                }
            },
            upHidden() {
                this.$emit('hideForm', false)
            },
            // 点击保存数据
            save(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.loading = true;
                        if (this.personalType == null && this.personalType === "" || this.personalType.length < 1) {
                            let role = this.dataList.custRole;
                            this.personalType = role;
                        }
                        let s = '';
                        if (this.formData.certEndDate != null && this.formData.certEndDate !== '') {
                            if (this.formData.certEndDate < new Date) {
                                this.loading = false;
                                return this.$Message.error("证件到期日必须大于当前时间");
                            }
                            s = formatDate(this.formData.certEndDate, "yyyy-MM-dd");
                        }
                        this.formData.birthday = formatDate(this.formData.birthday, 'yyyy-MM-dd');
                        if (this.formData.addressinfo[0].houseType !== null || this.formData.addressinfo[0].houseType !== '') {
                            if (this.formData.addressinfo[0].houseStartDate > new Date) {
                                this.$Message.error("房产起始时间不可大于当前时间");
                                this.loading = false;
                                return;
                            }
                        }
                        if (this.formData.certEndDate == null || this.formData.certEndDate === '') {
                            let date = '9999-12-31';
                            this.formData.certEndDate = date;
                        }
                        let param = {
                            applyNo: this.applyNo,
                            custRole: this.personalType,
                            //客户基础信息
                            applyCustBaseInfo: {
                                id: this.formData.id,
                                custType: this.formData.custType, //客户类型
                                custName: this.formData.custName, //客户姓名
                                telPhone: this.formData.telPhone, //手机号码
                                certType: this.formData.certType, //证件类型
                                certNo: this.formData.certNo, //证件编号
                                isLongTerm: this.formData.isLongTerm, //是否长期
                                certStartDate: this.formData.certStartDate,
                                certEndDate: this.formData.certEndDate, //证件失效日期
                                custRelation: this.formData.custRelation //与申请人关系
                            },
                            //个人信息
                            personalDetail: {
                                id: this.formData.personalInfoId,
                                personalAddressId: this.formData.personalAddressId,
                                permanentAdreess: this.formData.domicLocation,//户籍地址
                                spellName: this.formData.spellName, //姓名拼音
                                birthday: this.formData.birthday, //生日
                                maritalStatus: this.formData.maritalStatus, //婚姻状况
                                sex: this.formData.sex, //性别
                                age: this.formData.age,//年龄
                                highestEducation: this.formData.highestEducation, //最高学历
                                nationality: this.formData.nationality, //国籍
                                drivingType: this.formData.drivingType, //驾驶证件
                                drivingLicenceNo: this.formData.drivingLicenceNo, //驾驶证件号码
                                unitName: this.formData.unitName, //单位名称
                                unitNature: this.formData.unitNature, //单位性质
                                industryType: this.formData.industryType, //行业类型
                                jobsType: this.formData.jobsType, //职业类型
                                companyPhone: this.formData.companyPhone, //公司电话
                                monthlyIncome: this.formData.monthlyIncome, //月收入
                                totalIncome: this.formData.totalIncome, //家庭总收入
                                outstandingLoan: this.formData.outstandingLoan, //未结清贷款
                                workAge: this.formData.workAge, //工作年限
                                addressType: this.formData.addressType, //地址类型
                                position: this.formData.position,//职务
                            },
                        };
                        // 构造联系地址数据
                        let tempAdress = [];
                        for (let i = 0; i < this.formData.addressinfo.length; i++) {
                            let obj = {
                                id: this.formData.addressinfo[i].id,
                                addressType: this.formData.addressinfo[i].addressType,
                                houseType: this.formData.addressinfo[i].houseType,
                                houseStartDate: this.formData.addressinfo[i].houseStartDate,
                                detailAddress: this.formData.addressinfo[i].inputDetail,
                                detailAddressTemp: this.formData.addressinfo[i].detailAddressTemp,
                                isDefault: this.formData.addressinfo[i].isDefault,
                            }
                            tempAdress.push(obj);
                        }
                        param.addressDetailsList = tempAdress;
                        //如果存在id
                        if (this.formData.id != null && this.formData.id !== "" || this.formData.id.length > 0) {
                            updateCustomerInfo(param).then(res => {
                                if (res.code === "0000") {
                                    this.$Message.success("操作成功");
                                    if (this.formData.certEndDate <= new Date('9999-12-31') && this.formData.isLongTerm == true) {
                                        this.formData.certEndDate = null;
                                    }
                                    //保存成功返回客户信息页面
                                    this.$emit("close-model", false);
                                    this.$emit('queryInfo', this.personalType)
                                }
                            }).catch(() => {
                                this.loading = false;
                            });
                        } else {
                            saveCustomerInfo(param).then(res => {
                                if (res.code === "0000") {
                                    this.loading = false;
                                    this.$Message.success("操作成功");
                                    if (this.formData.certEndDate <= new Date('9999-12-31') && this.formData.isLongTerm == true) {
                                        this.formData.certEndDate = null;
                                    }
                                    //保存成功返回客户信息页面
                                    this.$emit("close-model", false);
                                    this.$emit('queryInfo', this.personalType)
                                }
                            }).catch(() => {
                                this.loading = false;
                            });
                        }
                    }
                })
            },
            cancel() {
                this.$emit("close-model", false);
                this.$emit('queryInfo', this.personalType);
            }
        }
    }
</script>
<style>
    .model .ivu-btn-success {
        background-color: green;
    }

    .model .ivu-modal {
        min-width: 1190px;
    }
</style>
<style scoped>
    .up {
        background-color: #fff;
    }

    .up > img {
        width: 16px;
        margin: 10px 20px 0 0;
        cursor: pointer;
    }

    .operBtn {
        text-align: center;
        margin: 10px 0;
    }

    .adresstype {
        border: 1px solid #DCDEE2;
        margin-bottom: 20px;
    }

    .adresstype h3 {
        background: #F6F6F6;
        border-bottom: 1px solid #DCDEE2;
        height: 40px;
        padding: 0 20px;
        margin-bottom: 10px;
        font-size: 13px;
        line-height: 40px;
    }

    .adresstype h3 > span {
        color: #EB9620;
        font-size: 12px;
        cursor: pointer;
        line-height: 20px;
        margin-top: 10px;
        float: right;
    }

    .adresstype h3 > span:hover {
        background: rgba(235, 150, 32, 0.25);
    }

    .adresstype h3 > span.del {
        color: #515a6e;
        margin-left: 20px;
    }

    .adresstype h3 > span.del:hover {
        color: #FF0010;
        background: transparent;
    }
</style>
